package com.dingwei.lesyndrome.mvp.presenter;

import com.dingwei.lesyndrome.base.FailsBean;
import com.dingwei.lesyndrome.base.MyBaseBean;
import com.dingwei.lesyndrome.bean.NewsInfoBean;
import com.dingwei.lesyndrome.custom.myCallback;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lihao on 2017/9/12.
 */

public class NewsDetailsPresenter extends basePresenter {

    private Contract.NewsDetailsView newsDetailsView;

    public NewsDetailsPresenter(Contract.NewsDetailsView view) {
        super(view);
        this.newsDetailsView = view;
    }

    public void initData(String id) {
        RequestParams rp = new RequestParams(URLS.HOST + URLS.NEWS_INFO);
        rp.addBodyParameter("id", id);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        x.http().post(rp, new myCallback(BaseActivity.context, NewsInfoBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                NewsInfoBean bean = (NewsInfoBean) baseBean;
                newsDetailsView.setData(bean);

            }

            @Override
            public void fail(FailsBean baseBean, String result) {
                newsDetailsView.onFail();
            }
        });
    }


    public void collect(String id) {
        RequestParams rp = new RequestParams(URLS.HOST+URLS.OPCOLLECT);
        rp.addBodyParameter("oid", id);
        rp.addBodyParameter("type", "2");
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        x.http().post(rp, new myCallback(BaseActivity.context, MyBaseBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                newsDetailsView.collectSuccess();
            }

            @Override
            public void fail(FailsBean baseBean, String result) {

            }
        });
    }
}
